package d;

import java.util.*;

//p210 任务实施
public class demo2 {
    public static void main(String[] args) {
        Map<String,String> hm = new HashMap<String,String>();
        hm.put("林黛玉","芙蓉花");
        hm.put("薛宝钗","牡丹花");
        hm.put("贾元春","昙花");
        hm.put("贾探春","杏花");
        hm.put("贾迎春","迎春花");
        hm.put("贾惜春","曼陀罗花");
        System.out.println("*********HashMap中的红楼梦十二金钗及对应花（无序）************");
        Set<String> keys = hm.keySet();
        Iterator it1 = keys.iterator();
        while (it1.hasNext()){
            String key = (String) it1.next();
            String value = (String) hm.get(key);
            System.out.println(key + "——" + value);
        }
        hm.remove("贾迎春");
        System.out.println("*******************************************************");
        System.out.println("删除\"贾迎春\"后HashMap中的红楼梦人物：" + hm);
        TreeMap<String,String> tm = new TreeMap<String,String>();
        tm.putAll(hm);
        System.out.println("*********TreeMap中的红楼梦十二金钗及对应花（有序）************");
        Iterator it2 = tm.keySet().iterator();
        while (it2.hasNext()){
            String key = (String) it2.next();
            System.out.println(key + ":" + tm.get(key));
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("*******************************************************");
        System.out.println("请输入金陵十二钗人物名（键）:");
        String key = scanner.next();
        System.out.println(key + "对应的化名为：" + tm.get(key));
    }
}
